﻿<div class="page-content-wrap">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-inline tool-btn">
                <button class="layui-btn layui-btn-small layui-btn-normal add_Btn hidden-xs" data-url="/Home/EditCategory"><i class="layui-icon">&#xe654;</i></button>
                <button class="layui-btn layui-btn-small layui-btn-danger del_Btn hidden-xs" data-id="list" data-url="/Home/deletecategory"><i class="layui-icon">&#xe640;</i></button>
            </div>
            <div class="layui-inline">
                <select id="Parentid" lay-verify="required">
                    <option>123</option>
                </select>
            </div>
            <button class="layui-btn layui-btn-normal" onclick="return false" id="search">搜索</button>
        </div>
    </form>
    <div class="layui-form" id="table-list" style="height: 400px;">
        <table id="list" class="layui-table"></table>
    </div>
</div>
@section script{
<script>
			$("#list").datagrid({
				 idField: 'id',
	            //singleSelect: false,
	            //rownumbers: true,
	            pagePosition: 'bottom',
	            pagination: true,//分页
	            pageSize: 100,//每页显示条数
	            pageList: [100, 150, 200, 250, 300, 350], //调整每页显示条数
	            fit: true,//宽高跟随父面板
	            fitColumns: true,//水平滚动条
	            nowrap: false,//折行显示
	            columns: [[
	            	{field:'check',checkbox:true, width: 100, align: 'center' },
	                { field: 'id', title: '栏目编号', width: 180, align: 'center' },
	                { field: 'cname', title: '栏目名称', width: 180, align: 'center' },
	                { field: 'pname', title: '模块名', width: 180, align: 'center' },
	                {field:'edit',title:'编辑',width:100,align:'center',
		                formatter: function(value,row,index){
		                    return '<button class="layui-btn layui-btn-mini layui-btn-normal edit_btn" data-id="' + row.id + '" data-url="/Home/UpdateCategory"><i class="layui-icon">&#xe642;</i></button>';
						}
	                }
	            ]],
            url: '/Home/categorytable',
			})
			$("#search").click(function(){
				$("#list").datagrid({
					queryParams: {
						Parentid: $("#Parentid").val()
					}
				});
			})
			layui.use(['form'], function() {
				var form = layui.form();
				var option= "<option value=''>请选择类型</option>";
				$.post("/Home/parenttable", function (datas) {
				 		 for(var i=0;i<datas.length;i++){
               				 option+="<option value='"+datas[i].id+"'>"+datas[i].pname+"</option>";//拼接option中的内容
                			$("#Parentid").html(option);//将option的拼接内容加入select中，注意选择器是select的ID
          			 }
				 		 form.render('select');
				})
				form.render();
			});
			//顶部批量删除
			$('.del_Btn').click(function () {
			    var id = "#" + $(this).attr("data-id");
			    var $table = $(id).datagrid('getChecked');
			    var no = new Array();
			    for (var i = 0; i < $table.length; i++) {
			        if (i == 0) {
			            no = "no=" + $table[i].id;
			        } else {
			            no += "&no=" + $table[i].id;
			        }
			    }
			    var url = $(this).attr('data-url');
			    layer.confirm('您确定要删除选中项?', function (index) {
			        //do something
			        $.get(url, no, function (data) {
			            layer.msg(data);
			            location.reload();
			        })
			        layer.close(index);
			    });
			    return false;
			});
			//顶部添加
			$('.add_Btn').click(function () {
			    var url = $(this).attr('data-url');
			    //将iframeObj传递给父级窗口,执行操作完成刷新
			    layer.open({
			        type: 2,
			        title: ["栏目添加"],
			        area: ['600px', '400px'],
			        content: url, //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
			        cancel: function () {
			            location.reload();
			        }
			    });
			    return false;
			});
			$('#table-list').on('click', '.edit_btn', function () {
			    var That = $(this);
			    var id = That.attr('data-id');
			    var url = That.attr('data-url');
			    //将iframeObj传递给父级窗口
			    layer.open({
			        type: 2,
                    title:["栏目添加"],
			        area: ['600px', '400px'],
			        content: url + "?id=" + id, //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
			        cancel: function () {
			            location.reload();
			        }
			    });
			    return false;
			})
</script>

}